using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Sigecov.Models.Mapping
{
    public class EstadoMap : EntityTypeConfiguration<Estado>
    {
        public EstadoMap()
        {
            // Primary Key
            this.HasKey(t => t.estId);

            // Properties
            this.Property(t => t.estNome)
                .IsRequired()
                .HasMaxLength(30);

            this.Property(t => t.estRegiao)
                .IsRequired()
                .HasMaxLength(30);

            // Table & Column Mappings
            this.ToTable("Estados");
            this.Property(t => t.estId).HasColumnName("estId");
            this.Property(t => t.estNome).HasColumnName("estNome");
            this.Property(t => t.estRegiao).HasColumnName("estRegiao");
            this.Property(t => t.paiId).HasColumnName("paiId");

            // Relationships
            this.HasRequired(t => t.Pais)
                .WithMany(t => t.Estados)
                .HasForeignKey(d => d.paiId);

        }
    }
}
